<template>
  <div class="box">
    <table-search
      slot="searchbar"
      v-model="searchData"
      :columns="searchOptions"
      @search="handleSearch"
    >
      <template slot="button">
        <a-button
          @click="handleExport"
          icon="download"
          style="color: #606266"
          slot="button"
          type="link"
        >
          导出
        </a-button>
        <!-- <a-button
          @click="handleAdd"
          icon="plus"
          style="color: #606266"
          slot="button"
          type="link"
        >
          添加
        </a-button> -->
      </template>
    </table-search>
    <div class="table-box">
      <div class="table-cards">
        <card title="商品数量" :num="1451" unit="件" />
        <card title="订单数量" :num="1451" unit="个" />
        <card title="销售金额" :num="1611244.14" unit="元" :decimals="true" />
      </div>
      <a-table
        :columns="columns"
        :data-source="data"
        size="middle"
        :scroll="{ x: 1040 }"
        :pagination="false"
      >
        <template slot="index" slot-scope="scope">{{ scope.key }}</template>
        <template slot-scope="scope" slot="action">
          <a-button
            style="color: #2a5ee3"
            type="link"
            @click="handleEdit(scope)"
            size="small"
          >
            小票图片
          </a-button>
          <!-- <a-button
            style="color: #f34f4a"
            type="link"
            @click="handleDelete(scope)"
            size="small"
          >
            删除
          </a-button> -->
        </template>
      </a-table>
      <div class="pagination-box">
        <a-pagination
          show-quick-jumper
          @change="handleChange"
          :show-total="(total) => `共 ${total} 条`"
          :defaultCurrent="pagination.current"
          :pageSize="pagination.pageSize"
          :total="pagination.total"
          :hideOnSinglePage="true"
        />
      </div>
    </div>
    <a-modal
      class="order-box"
      :visible="visible"
      width="370px"
      :footer="null"
      :title="null"
    >
      <template slot="closeIcon">
        <div
          style="
            width: 100%;
            height: 100%;
            position: absolute;
            top: -50%;
            right: -50%;
          "
          @click="handleCancel"
        >
          <a-icon type="close" />
        </div>
      </template>
      <div class="modal-content"><img onerror="加载失败" src="" alt="" /></div>
    </a-modal>
  </div>
</template>

<script>
import columns from "./colums";
import card from "@/components/card";
export default {
  components: {
    card,
  },
  data() {
    return {
      visible: false,
      columns,
      data: [
        {
          key: "1",
          supermarketName: "孙武三泽购物广场",
          taxpayer: "7号收银机(141)",
          creditCode: "6",
          legal: "52.30",
          phone: "2021-02-15   14:15:43",
        },
        {
          key: "2",
          supermarketName: "孙武三泽购物广场",
          taxpayer: "7号收银机(141)",
          creditCode: "6",
          legal: "52.30",
          phone: "2021-02-15   14:15:43",
        },
      ],
      pagination: {
        total: 50,
        current: 1,
        pageSize: 10,
      },
      searchData: {},
      searchOptions: [
        {
          type: "daterange",
          label: "日期",
          prop: "supermarketName",
        },
        {
          type: "select",
          label: "超市名称",
          prop: "taxation",
          attrs: {
            filterable: true,
          },
          enums: [
            {
              label: "石庙镇",
              value: "1",
            },
          ],
        },
        {
          type: "text",
          label: "商品名称",
          prop: "legal",
        },
      ],
    };
  },
  methods: {
    handleSearch(val) {
      console.log(val, "查询");
    },
    handleEdit(val) {
      this.visible = true;
      console.log(val, "小票图片");
    },
    handleDelete(val) {
      console.log(val, "删除");
    },
    handleChange(page, pageSize) {
      console.log(page, pageSize, "分页");
    },
    handleExport() {
      console.log("导出");
    },
    handleAdd() {
      console.log("添加");
    },
    handleCancel() {
      this.visible = false;
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  .table-box {
    padding-top: 30px;
  }
  .pagination-box {
    text-align: right;
    // position: absolute;
    // bottom: 40px;
    // right: 16px;
    padding-top: 40px;
    .ant-pagination {
      display: inline-block;
    }
  }
}
.modal-content {
  width: calc(100% + 12px);
  min-height: 200px;
  max-height: 590px;
  overflow-x: hidden;
  vertical-align: middle;
  text-align: center;
  line-height: 200px;
  background: rgb(238, 238, 238);
  img {
    width: 100%;
    vertical-align: middle;
  }
}
.table-cards {
  display: flex;
}
@media screen and (max-width: 1250px) {
  .table-cards {
    display: block;
  }
}
</style>
